define(function () {

    var self, userInfo,product;

    function jdcx() {
        self = this;
        self.mData = {
            tabType: ['1', '2'],
            productList: {}
        };
        self.searchData = {
            keyword: ''
        };
        userInfo = app.userInfos.sysUser;
        self.list = [];
        self.GWAK030 = userInfo.MOBILE;
        self.currentIndex = 0;
        self.init();
    }

    jdcx.prototype.getData = function (product) {
        var gwaa = app.userInfos.user;
        app.ajax({
            xurl: 'api/wx/jdcx/getProgressListData',
            // xtime:'1d',
            xdata: {
                page:product.page+1,
                limit: product.limit,
                MMRD020: product.type,
                GWAK030: self.GWAK030,
                keyword: self.searchData.keyword,//输入的查询条件
                GWAA007:gwaa.GWAA007 //需判断是否为内部员工还是外部员工

            },
            cb: function (result) {
                if (result.ok) {
                    if (product.page == 0) {
                        product.data.removeAll();
                    }
                    product.data.pushArray(result.data.data);

                    var refresh = product.refresh;
                    if (product.page == 0) {
                        refresh.endPulldownToRefresh();
                        if (result.data.data.length == 0) {
                            app.showNoData(product._tip, self.currentIndex == 0 ? '无未完工的进度...' : '无已完工的进度...');
                            refresh.disablePullupToRefresh();
                        } else {
                            app.hideNoData(product._tip);
                            refresh.refresh(true);
                        }
                    }
                    product.page += 1;
                    refresh.endPullupToRefresh(result.data.data.length < product.limit);
                }
            }
        });
    };

    jdcx.prototype.initVue = function () {
        //查询栏位
        var search = new Vue({
            el: document.getElementById('search'),
            data: {
                keyword:''
            },
            methods:{
                toSearch: function () {
                    self.searchData.keyword = search.keyword;
                    self.mData.productList[self.mData.tabType[self.currentIndex]].refresh.pulldownLoading();
                }
            }
        })



    }

    jdcx.prototype.init = function () {
        self.initVue();
        mui.ready(function () {

            var refreshData = function (i) {
                var _type = self.mData.tabType[i];
                product = self.mData.productList[_type];
                if (!product) {
                    product = self.mData.productList[_type] = {
                        page: 1,
                        limit: 15,
                        data: [],
                        start: function () {
                            return (this.page) * this.limit;
                        },
                        type: _type
                    };

                    //进度列表
                    new Vue({
                        el: doc.getElementById('scroll' + _type),
                        data: {
                            list : product.data
                        },
                        methods: {
                            open: function (item) {
                                app.openPage({
                                    src: 'jdcx/jdcx-info.html',
                                    argsKey: 'jdcxinfo_page',
                                    args: item
                                });
                            },
                            jindu: function (value) {
                                if (value == 1) {
                                    return '发起';
                                } else if (value == 2) {
                                    return '受理';
                                } else if (value == 3) {
                                    return '派工';
                                } else if (value == 4) {
                                    return '报工';
                                } else if (value == 5) {
                                    return '评价';
                                } else if (value == 6) {
                                    return '回访结案';
                                }
                            }
                        }
                    });

                    product._tip = $('#scroll' + _type);
                    product.refresh = mui('#scroll' + _type).pullRefresh({
                        down: {
                            callback: function () {
                                product.page = 0;
                                self.getData(product);
                            },
                            auto: true
                        }, up: {
                            callback: function () {
                                self.getData(product);
                            }
                        }
                    });
                }
            };
            refreshData(0);

            setTimeout(function () {

                doc.getElementById('slider').addEventListener('slide', function (e) {
                    self.currentIndex = e.detail.slideNumber;
                    refreshData(self.currentIndex);
                });

            }, 200);

        })
    }

    return new jdcx();
});
